<?php
namespace Api\Controller;
use Common\Controller\AdminbaseController;
class GuestbookadminController extends AdminbaseController{
	
	protected $guestbook_model;
	
	function _initialize() {
		parent::_initialize();
		$this->guestbook_model=D("Common/Guestbook");
	}
	
	function index(){
		$count=$this->guestbook_model->count(); // 这里删除了where(array("status"=>1))
		$page = $this->page($count, 20);
		$guestmsgs=$this->guestbook_model->order(array("createtime"=>"DESC"))->limit($page->firstRow . ',' . $page->listRows)->select();//此处也删除了条件->where(array("status"=>1))
		$this->assign("Page", $page->show('Admin'));
		$this->assign("guestmsgs",$guestmsgs);
		$this->display();
	}

	function delete(){
		$id=intval(I("get.id"));
		$result=$this->guestbook_model->where(array("id"=>$id))->delete();
		if($result!==false){
			$this->success("删除成功！", U("Guestbookadmin/index"));
		}else{
			$this->error('删除失败！');
		}
	}
	function edit(){
		//dump($_POST);
		$id=intval(I('get.id')); //get方式提交的数据
		$guestinfo=$this->guestbook_model->where(array("id"=>$id))->find();
		//dump($guestinfo);		
		$this -> assign('guestinfo',$guestinfo);
		$this -> display();
	}
	function doedit(){		
		$id=intval(I('post.id'));
		//dump($_POST);
		$result=$this->guestbook_model->where(array("id"=>$id))->save($_POST);
		//dump($this->guestbook_model->getLastSql());	打印sql语句	
		if($result!==false){
			$this->success("修改成功！", U("Guestbookadmin/index"));
		}else{
			$this->error('保存失败！');
		}
	}
	//function reply(){
		//dump($_POST);
		//$id=intval(I('get.id')); //get方式提交的数据
		//$guestinfo=$this->guestbook_model->where(array("id"=>$id))->find();
		//dump($guestinfo);		
		//$this -> assign('guestinfo',$guestinfo);
		//$this -> display();
	//}
	//function doreply(){		
		//$id=intval(I('post.id'));
		//dump($_POST);
		//$result=$this->guestbook_model->where(array("id"=>$id))->save($_POST);
		//dump($this->guestbook_model->getLastSql());	打印sql语句	
		//if($result!==false){
			//$this->success("回复成功！", U("Guestbookadmin/index"));
		//}else{
			//$this->error('回复失败！');
		//}
	//}
}